<template>
  <div class="body">
    <div class="top">
      <el-form size="mini" :inline="true">
        <el-form-item label="工单编号：">
          <el-input v-model="data.orderNo" placeholder="请输入" style="width:180px" />
        </el-form-item>
        <el-form-item label="工单状态：">
          <template>
            <el-date-picker
              v-model="time"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            />
          </template>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="chaxun">
            <i class="el-icon-search" />
            查询</el-button>
        </el-form-item>
      </el-form>

    </div>
    <div class="list">
      <el-table :data="list">
        <el-table-column type="index" label="序号">
          <template scope="scope">
            <span>{{ (data.pageIndex-1)*data.pageSize+scope.$index+1 }}</span>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="订单编号">
          <template v-slot="{ row }">
            <span>{{ row.orderNo }}</span>
          </template>
        </el-table-column>
        <el-table-column label="商品名称">
          <template v-slot="{ row }">
            <span>{{ row.skuName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单金额（元）">
          <template v-slot="{ row }">
            <span>{{ row?.amount / 100 }}</span>
          </template>

        </el-table-column>
        <el-table-column label="设备编号">
          <template v-slot="{ row }">
            <span>{{ row.innerCode }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单状态">
          <template v-slot="{ row }">
            <span>{{ statuslist[ row.status] }}</span>
          </template>
        </el-table-column>
        <el-table-column width="180px" label="订单日期">
          <template v-slot="{ row }">
            <span>{{ $dayjs(row.createTime).format('YYYY.MM.DD HH:mm:ss') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template v-slot="{ row }">
            <el-button type="text" @click="particulars(row)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-row type="flex" style="height:60px" align="middle" justify="space-between">
        <span class="record">共{{ totalCount }}条记录 第{{ data.pageIndex }}/ {{ totalPage }} 页</span>
        <el-pagination
          :page-size="data.pagesize"
          :current-page="data.pageIndex"
          layout="prev,  next"
          :total="+totalCount"
          prev-text="上一页"
          next-text="下一页"

          @current-change="changePage"
        />
      </el-row>
    </div>
    <!-- 工单详情 -->
    <el-dialog
      title="工单详情"
      :visible.sync="WorkOrderDetails"
      width="45%"
      :before-close="handleClose"
    >
      <div v-if="myRow.status === 2" class="rowTop">
        <div class="topImg">
          <img src="~@/assets/wcmin.png" alt="">
          <span>{{ statuslist[myRow.status] }}</span>
        </div>
        <img class="footImg" src="~@/assets/wcmax.png" alt="">
      </div>
      <div v-else class="rowTop">
        <div class="topImg">
          <img src="~@/assets/qxmin.png" alt="">
          <span>{{ statuslist[myRow.status] }}</span>
        </div>
        <img class="footImg" src="~@/assets/qxmax.png" alt="">
      </div>
      <el-row class="rowFooter">
        <el-col :span="12">
          <el-form>
            <el-form-item label="订单编号：">
              <span>{{ myRow.orderNo }}</span>
            </el-form-item>
            <el-form-item label="设备编号：">
              <span>{{ myRow.innerCode }}</span>
            </el-form-item>
            <el-form-item label="完成时间：">
              <span>{{ $dayjs(myRow.updateTime).format('YYYY.MM.DD HH:mm:ss') }}</span>
            </el-form-item>
            <el-form-item label="设备地址：">
              <span>{{ myRow.addr }}</span>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="12">
          <el-form>
            <el-form-item label="商品名称：">
              <span>{{ myRow.skuName }}</span>
            </el-form-item>
            <el-form-item label="订单金额：">
              <span>{{ myRow.amount / 100 }}</span>
            </el-form-item>
            <el-form-item label="创建时间：">
              <span>{{ $dayjs(myRow.createTime).format('YYYY.MM.DD HH:mm:ss') }}</span>
            </el-form-item>
            <el-form-item label="支付方式：">
              <span>{{ zhifu[ myRow.payType ] }}</span>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>
<script>
import { getTypeList } from '@/api/employee'
import { getDingdan } from '@/api/social'
import dayjs from 'dayjs'
export default {
  name: 'Social',
  data() {
    return {
      num: 1,
      WorkOrderDetails: false,
      // 工单列表
      list: [],

      // 映射表
      yingshebiao: {
        0: '自动',
        1: '手动'
      },
      statuslist:
        {
          0: '创建',
          1: '支付完成',
          2: '出货成功',
          3: '出货成功'
        },
      // 支付方式
      zhifu: {
        1: '支付宝',
        2: '微信'
      },
      data: {
        pageIndex: 1,
        pageSize: 10,
        orderNo: '',
        startDate: '',
        endDate: ''
      },
      time: '',
      totalCount: 0,
      totalPage: 0,
      dialogVisible: false,
      myRow: {},
      value1: ''
    }
  },
  async created() {
    this.getRole()
    this.TypeList()
  },
  methods: {
    async TypeList() {
      const res = await getTypeList()
      this.arrTypeList = res
      console.log(res)
    },
    // 渲染页面
    async getRole() {
      const res = await getDingdan(this.data)
      this.list = res.currentPageRecords
      this.totalCount = res.totalCount
      this.totalPage = res.totalPage
      console.log(this.list)
    },
    // 查询
    async chaxun() {
      if (this.time[1]) {
        this.data.startDate = dayjs(this.time[0]).format('YYYY-MM-DD')
        this.data.endDate = dayjs(this.time[1]).format('YYYY-MM-DD')
      }
      await this.getRole()
      this.data.startDate = ''
      this.data.endDate = ''
      this.time = ''
    },
    // 分页更新
    changePage(newPage) {
      // console.log(newPage)
      this.data.pageIndex = newPage
      // console.log(this.data)
      this.getRole()
    },
    // 关闭弹窗
    handleClose() {
      this.WorkOrderDetails = false
    },
    // 查看详情
    async particulars(row) {
      this.myRow = row
      this.WorkOrderDetails = true
      // console.log(this.particularsList)
    }
  }

}
</script>

<style lang='scss' scoped>
.body{
  .top{
    height: 60px;
    margin: 20px;
    padding: 18px;
    background-color: #fff;
  }
  .list{
    padding: 18px;
    margin: 20px;
    background-color: #fff;
   }
}
      .quxiaogongdan{
        margin-top: 30px;
       width: 100%;
       display: flex;
       justify-content: center;
       .qxbutton{
        transform:translateX(-50%);
       }

     }
    ::v-deep.el-pagination .btn-next{
  background-color: #d5ddf8 !important;
  width: 70px;
  height: 30px;
  text-align: center;
  border-radius: 3px;
   margin: 10px;
}

::v-deep.el-pagination .btn-prev{
  background-color: #d5ddf8 !important;
  width: 70px;
  height: 30px;
  text-align: center;
  border-radius: 3px;
  margin: 10px;
}
.record{
  color: #dbdfe5;
}
.rowFooter{
  padding-left: 40px;
}
.grid-content{
  padding: 8px;
}
::v-deep.WorkOrderDetailsBtn{
  padding: 0;
  margin: 0;
}
.rowTop{
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    justify-content: space-between;
    align-items: center;
    height: 54px;
    margin-bottom: 25px;
    background-color: hsla(0,0%,92.5%,.39);
  .topImg{
    display: flex;
    align-items: center;
    height: 54px;
    background-color: hsla(0,0%,92.5%,.39);
    img{
      padding:0 25px ;
    }
  }
  .footImg{
      margin-right: 76px;
    margin-bottom: 7px;
  }
}
</style>
